

<h1>Inscrições</h1>
<br />


<% unless logged_in? %>

	<%= login_required_message %>

<% else %>

    <% unless current_user.has_attendee? %>
				<%= render :partial => 'no_attendee' %>
    <% else %>

		 <%= render :partial => 'data' %>

     <% if authorized? %>

        <br />
        <%= render :partial => 'small_model', :locals => {:attendee => @attendee[0] } %>

		<br />
		<h2>Buscas</h2>
		<p> Use as opções abaixo para filtrar os inscritos pelos critérios desejados </p>


		<%# OMG this section needs refactoring %>

		<%
			def url_choice
				parameters = params.to_a.map {|x| "#{x[0]}=#{x[1]}" if /^mostrar/.match(x[0]) }.select {|x| x }
				attendees_path + "?" + parameters.join('&')
			end
		%>

		<% choices = ["pagos",
			  "npagos",
			  "alojamento",
			  "nalojamento",
			  "ufrgs",
			  "pucrs",
			  "tutor",
			  "ntutor",
			  "fila",
			  "nfila",
			  "cancelado",
			  "ncancelado"] %>
		<table>
		<tr>
		<% choices.each_with_index do |c,i| %>

        	      <td> <%= link_to c.capitalize, url_choice + "&mostrar#{i}=#{c}"    %> </td>
        	      	<% if ((i+1) % 4) == 0 %>
						</tr> <tr>
        	      	<% end %>

        <% end %>
        </tr>
		</table>


		<%= content_tag("p", "#{@attendees.size} inscritos foram encontrados com estes critérios.", :style => 'font-weight: bold') %>

		<p>
            <%= link_to "Mostrar bonito", url_choice + '&bonito=sim', :class => 'button'  %>
        </p>

		<p>
            <%= link_to "Resetar buscas", attendees_path, :class => 'button'  %>
        </p>

    <% end %>

   	 <%= render :partial => 'display_attendees', :locals => {:at => @attendees} %>

  <% end %>

	<%#= will_paginate @attendees, options = pagination_options if authorized? %>

<% end %>

<%= render :partial => "rules" unless authorized? %>
